<!-- NowTicketInfo -->
<template>
  <div>
    <el-card class="box-card box-cardCustomer">
      <div slot="header"
           class="clearfix"
           @click="changeArrow">
        <div style="display:flex;justify-content: space-between">
          <div style="display:flex;align-items:center">
            <img class="firstIcon"
                 src="@/assets/ticket/review.png">
            <!-- <el-tooltip :open-delay="1000" class="item" effect="dark" content="Copy ticket number" placement="top">
              <img src="@/assets/ticket/copy.png"
                  style="margin-left:10px"
                  v-if="nextTicketInfo.id"
                  @click.stop="copyTicketId(nextTicketInfo.id ?nextTicketInfo.id:'')">
            </el-tooltip> -->
            <!-- <el-tooltip :open-delay="1000" class="item" effect="dark" content="Click to open this ticket in AutoTask" placement="top">
              <span class="span1" @click.stop="toTicket(nextTicketInfo.id ?nextTicketInfo.id:'')">[{{ nextTicketInfo.entity&&nextTicketInfo.entity.ticketNumber ?nextTicketInfo.entity.ticketNumber:''}}]</span>
            </el-tooltip> -->
            <!-- <span class="span_"> - </span> -->
            <span style="margin-left:10px">{{$t('custom.component.gadget.company')}}:</span>
            <span v-if="nextTicketType.replace('dataset','')  === 'autotask'"
                  class="span2"
                  style="display:inline-block;margin-left:4px">{{ nextTicketInfo.entity&&nextTicketInfo.entity.companyIDName ?nextTicketInfo.entity.companyIDName:''}}</span>
            <span v-if="nextTicketType.replace('dataset','')  === 'kaseyabms'"
                  class="span2"
                  style="display:inline-block;margin-left:4px">{{ nextTicketInfo.entity&&nextTicketInfo.entity.AccountName ?nextTicketInfo.entity.AccountName:''}}</span>
            <span v-else
                  class="span2"
                  style="display:inline-block;margin-left:4px">{{ nextTicketInfo.entity&&nextTicketInfo.entity.company ?nextTicketInfo.entity.company.name:''}}</span>
          </div>
          <div class="rightContent"
               style="display:flex;align-items:center">
            <!-- <span>|</span>
             <el-tooltip :open-delay="1000" class="item" effect="dark" content="Click to open this ticket in AutoTask" placement="top">
                <img src="https://oss.mspbots.ai/files/autotask.png"
                 @click.stop="toTicket(nextTicketInfo.id ?nextTicketInfo.id:'')">
              </el-tooltip> -->

            <el-icon :class="arrowCustomer"></el-icon>
          </div>
        </div>
      </div>
      <el-collapse-transition v-if="nextTicketType.replace('dataset','')  === 'autotask'">
        <div v-if="showPanel&&nextTicketInfo.entity"
             class="box-cardCustomer-content">
          <el-row class="table1row">
            <el-col :span="6">{{$t('custom.component.gadget.companyName')}}:</el-col>
            <el-col :span="18">{{ nextTicketInfo.entity&&nextTicketInfo.entity.companyIDName?nextTicketInfo.entity.companyIDName:'' }}</el-col>
          </el-row>
          <el-row class="table1row">
            <el-col :span="6">{{$t('custom.component.gadget.location')}}:</el-col>
            <el-col :span="18">{{ nextTicketInfo.entity&&nextTicketInfo.entity.companyCity?nextTicketInfo.entity.companyCity:'' }}</el-col>
          </el-row>
          <el-row class="table1row">
            <el-col :span="6">{{$t('custom.component.gadget.contactName')}}:</el-col>
            <el-col :span="18">{{ nextTicketInfo.entity&&nextTicketInfo.entity.contactIDName?nextTicketInfo.entity.contactIDName:'' }}</el-col>
          </el-row>
          <el-row class="table1row">
            <el-col :span="6">{{$t('custom.component.gadget.phone')}}:</el-col>
            <el-col :span="18">{{ nextTicketInfo.entity&&nextTicketInfo.entity.companyPhone ? nextTicketInfo.entity.companyPhone:''}}</el-col>
          </el-row>
          <el-row class="table1row">
            <el-col :span="6">{{$t('custom.component.gadget.email')}}:</el-col>
            <el-col :span="18">{{ nextTicketInfo.entity&&nextTicketInfo.entity.assignedResourceEmail ? nextTicketInfo.entity.assignedResourceEmail:''}}</el-col>
          </el-row>
        </div>
      </el-collapse-transition>
      <el-collapse-transition v-else-if="nextTicketType.replace('dataset','')  === 'kaseyabms'">
        <div v-if="showPanel"
             class="box-cardCustomer-content">
          <el-row class="table1row">
            <el-col :span="6">{{$t('custom.component.gadget.companyName')}}:</el-col>
            <el-col :span="18">{{ nextTicketInfo.entity&&nextTicketInfo.entity&&nextTicketInfo.entity.AccountName?nextTicketInfo.entity.AccountName:'' }}</el-col>
          </el-row>
          <el-row class="table1row">
            <el-col :span="6">{{$t('custom.component.gadget.location')}}:</el-col>
            <el-col :span="18">{{ nextTicketInfo.entity&&nextTicketInfo.entity&&nextTicketInfo.entity.AccountLocation?nextTicketInfo.entity.AccountLocation:'' }}</el-col>
          </el-row>
          <el-row class="table1row">
            <el-col :span="6">{{$t('custom.component.gadget.contactName')}}:</el-col>
            <el-col :span="18">{{ nextTicketInfo.entity&&nextTicketInfo.entity.ContactFirstName&&nextTicketInfo.entity.ContactFirstName&&nextTicketInfo.entity.ContactLastName?nextTicketInfo.entity.ContactFirstName + ' '+ nextTicketInfo.entity.ContactLastName:'' }}</el-col>
          </el-row>
          <el-row class="table1row">
            <el-col :span="6">{{$t('custom.component.gadget.phone')}}:</el-col>
            <el-col :span="18">{{ nextTicketInfo.entity&&nextTicketInfo.entity&&nextTicketInfo.entity.ContactData&&nextTicketInfo.entity.ContactData.Phone ? nextTicketInfo.entity.ContactData.Phone:''}}</el-col>
          </el-row>
          <el-row class="table1row">
            <el-col :span="6">{{$t('custom.component.gadget.email')}}:</el-col>
            <el-col :span="18">{{ nextTicketInfo.entity&&nextTicketInfo.entity&&nextTicketInfo.entity.ContactData&&nextTicketInfo.entity.ContactData.Email ? nextTicketInfo.entity.ContactData.Email:''}}</el-col>
          </el-row>
        </div>
      </el-collapse-transition>
      <el-collapse-transition v-else>
        <div v-if="showPanel&&nextTicketInfo.entity"
             class="box-cardCustomer-content">
          <el-row class="table1row">
            <el-col :span="6">{{$t('custom.component.gadget.companyName')}}:</el-col>
            <el-col :span="18">{{ nextTicketInfo.entity&&nextTicketInfo.entity.company?nextTicketInfo.entity.company.name:'' }}</el-col>
          </el-row>
           <el-row class="table1row">
            <el-col :span="6">{{$t('custom.component.gadget.contactName')}}:</el-col>
            <el-col :span="18">{{ nextTicketInfo.entity&&nextTicketInfo.entity.contactName?nextTicketInfo.entity.contactName:'' }}</el-col>
          </el-row>
          <el-row class="table1row">
            <el-col :span="6">{{$t('custom.component.gadget.phone')}}:</el-col>
            <el-col :span="18">{{ nextTicketInfo.entity&&nextTicketInfo.entity.contactPhoneNumber ? nextTicketInfo.entity.contactPhoneNumber:''}}</el-col>
          </el-row>
          <el-row class="table1row">
            <el-col :span="6">{{$t('custom.component.gadget.email')}}:</el-col>
            <el-col :span="18">{{ nextTicketInfo.entity&&nextTicketInfo.entity.contactEmailAddress ? nextTicketInfo.entity.contactEmailAddress:''}}</el-col>
          </el-row>
          <el-row class="table1row">
            <el-col :span="6">{{$t('custom.component.gadget.site')}}:</el-col>
            <el-col :span="18">{{ nextTicketInfo.entity&&nextTicketInfo.entity.site ? nextTicketInfo.entity.site.name:''}}</el-col>
          </el-row>
          <el-row class="table1row">
            <el-col :span="6">{{$t('custom.component.gadget.address')}} 1:</el-col>
            <el-col :span="18">{{ nextTicketInfo.entity&&nextTicketInfo.entity.addressLine1 ? nextTicketInfo.entity.addressLine1:''}}</el-col>
          </el-row>
          <el-row class="table1row">
            <el-col :span="6">{{$t('custom.component.gadget.address')}} 2:</el-col>
            <el-col :span="18">{{ nextTicketInfo.entity&&nextTicketInfo.entity.addressLine2 ? nextTicketInfo.entity.addressLine2:''}}</el-col>
          </el-row>
          <el-row class="table1row">
            <el-col :span="6">{{$t('custom.component.gadget.city')}}:</el-col>
            <el-col :span="18">{{ nextTicketInfo.entity&&nextTicketInfo.entity.city ? nextTicketInfo.entity.city:''}}</el-col>
          </el-row>
         <el-row class="table1row">
            <el-col :span="6">{{$t('custom.component.gadget.state')}}:</el-col>
            <el-col :span="18">{{ nextTicketInfo.entity&&nextTicketInfo.entity.stateIdentifier ? nextTicketInfo.entity.stateIdentifier:''}}</el-col>
          </el-row>
          <el-row class="table1row">
            <el-col :span="6">{{$t('custom.component.gadget.zip')}}:</el-col>
            <el-col :span="18">{{ nextTicketInfo.entity&&nextTicketInfo.entity.zip ? nextTicketInfo.entity.zip:''}}</el-col>
          </el-row>

        </div>
      </el-collapse-transition>
    </el-card>
  </div>
</template>

<script>
import { GlobalTimeformat } from '@/utils/common'
export default {
  props: {
    nextTicketInfoCopy: {
      type: Object,
      default: function () {
        return {}
      }
    },
    nextTicketType: {
      type: String,
      default: null
    }
  },
  data () {
    return {
      arrowCustomer: 'el-collapse-item__arrow el-icon-arrow-right is-active  el-icon-arrowCustomer',
      showPanel: true,
      activePannel: ['pannel'],
      nextTicketInfo: this.nextTicketInfoCopy
    }
  },
  watch: {
    nextTicketInfoCopy: {
      handler: function (val) {
        this.nextTicketInfo = val
      },
      deep: true
    }
  },
  created () {
  },
  methods: {
    timeformat (time) {
      return GlobalTimeformat(time, 'HH:mm')
    },
    changeArrow () {
      this.arrowCustomer = this.arrowCustomer === 'el-collapse-item__arrow el-icon-arrow-right el-icon-arrowCustomer'
        ? 'el-collapse-item__arrow el-icon-arrow-right is-active  el-icon-arrowCustomer'
        : 'el-collapse-item__arrow el-icon-arrow-right el-icon-arrowCustomer'
      this.showPanel = !this.showPanel
    },
    toTicket (val) {
      if (!val) {
        return this.$message.error('Please Select filter')
      }
      if (this.nextTicketInfo && this.nextTicketInfo.entity && this.nextTicketInfo.entity.link) {
        const url = this.nextTicketInfo.entity.link
        window.open(url, '_blank')
      }
    },
    copyTicketId (data) {
      if (!data) {
        return this.$message.error('No Ticket Id!')
      }
      const url = data
      const oInput = document.createElement('input')
      oInput.value = url
      document.body.appendChild(oInput)
      oInput.select()
      document.execCommand('Copy')
      oInput.remove()
      this.$message.success('Copy Success')
    }
  }
}
</script>
<style lang="scss">
.box-cardCustomer {
  .el-card__body {
    padding: 0px !important;
  }
  .el-card__header {
    cursor: pointer;
    height: 59px;
    padding: 18px 10px;
  }
  .firstIcon {
    height: 20px;
    width: 20px;
    margin-top: -4px;
  }
  .span1 {
    margin-left: 10px;
    color: #fa8c16;
    font-size: 16px;
    font-weight: 500;
    text-decoration: underline;
  }
  .span_ {
    margin-left: 5px;
    color: #fa8c16;
    font-size: 16px;
    font-weight: 500;
  }
  .span2 {
    /* margin-left: 10px; */
    color: #138dc7;
    font-size: 16px;
    font-weight: 500;
  }
  .table1row {
    line-height: 30px;
    /* margin-left: 30px; */
    text-align: left;
  }
  .table1row > div:nth-child(1) {
    font-size: 14px;
    font-weight: 600;
    color: rgba(0, 0, 0, 0.5);
  }
  .table1row > div:nth-child(2) {
    font-size: 14px;
    font-weight: 400;
    color: #000000;
  }
  .box-cardCustomer-content {
    padding: 20px 10px 20px 40px;
  }
  .clearfix {
    vertical-align: middle;
    text-align: left;
  }
  .el-icon-arrowCustomer {
    float: right;
    padding: 3px 0;
  }
  .rightContent {
    display: flex;
  }
  .rightContent > img {
    height: 20px;
    width: 20px;
    margin-right: 10px;
  }
  .rightContent > span {
    margin-right: 10px;
    color: #f0f0f0;
  }
}
</style>
